<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="<?php echo site_url("style.css"); ?>" type="text/css" />
<title>Edit Entry</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>
	<!-- header starts here -->
<div id="header">
  <div id="header-content"> 
    <ul>
      <li><a href="<?php echo site_url("admin/logout/"); ?>">Logout</a></li>
    </ul>
  </div>
</div>

<div id="content-wrap">
	
	<div id="nav">
		<img src="<?php echo site_url("images/Nav_Head.png"); ?>" alt="navigation header" class="no-border" />
		<a href="<?php echo site_url("review"); ?>"><img src="<?php echo site_url("images/Home_On.png"); ?>" alt="home" class="no-border" /></a>
		<a href="<?php echo site_url("review/reviews/default/0/A"); ?>"><img src="<?php echo site_url("images/Reviews_Off.png"); ?>" alt="reviews" class="no-border" /></a>
		<br />
		<div class="navlink"><a href="<?php echo site_url("admin/post/"); ?>">Add Post</a></div><br />
		<div class="navlink"><a href="<?php echo site_url("admin/add_series/"); ?>">Add Series</a></div><br />
		<div class="navlink"><a href="<?php echo site_url("admin/edit/post/0"); ?>">Edit Post/Review</a></div><br />
		<div class="navlink"><a href="<?php echo site_url("admin/edit/series/0"); ?>">Edit Series</a></div><br />
        <div class="navlink"><a href="<?php echo site_url("admin/manage_list/0"); ?>">Media Management</a></div><br />
		<div class="navlink"><a href="<?php echo site_url("admin/edit_schedule/"); ?>">Edit Schedule</a></div><br />
	</div>
		
	<div id="adminwrapper">
<?php   
    $title = htmlspecialchars($post->title);
	$cont = nl2br($post->content);
	echo "<h1>$title</h1>
		<h3>Posted by: $post->poster @ $post->posted [Last Modified: $post->modified]</h3>
		<p>Type: $post->class <br />
		Series: $post->series <br />
		Episode: $post->episode </p><br />
		<p>$cont</p><br /><br />";
?>
<script language="JavaScript" type="text/JavaScript">
	var imageblocks = 0;

	function insertAtCaret(areaId,text) { 
	var txtarea = document.getElementById(areaId); 
	var scrollPos = txtarea.scrollTop; 
	var strPos = 0; 
	var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) ); 
		if (br == "ie") { txtarea.focus(); 
			var range = document.selection.createRange(); 
			range.moveStart ('character', -txtarea.value.length); 
			strPos = range.text.length; 
		} else if (br == "ff") strPos = txtarea.selectionStart; 
				var front = (txtarea.value).substring(0,strPos); 
				var back = (txtarea.value).substring(strPos,txtarea.value.length); 
				txtarea.value=front+text+back; 
				strPos = strPos + text.length; 
				if (br == "ie") { txtarea.focus(); 
					var range = document.selection.createRange(); 
					range.moveStart ('character', -txtarea.value.length); 
					range.moveStart ('character', strPos); 
					range.moveEnd ('character', 0); 
					range.select(); 
				} else if (br == "ff") { txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus(); 
					} 
			txtarea.scrollTop = scrollPos; 
		}
		
	function imgblk(areaId) {
	var text = '##' + imageblocks + '#';
	var txtarea = document.getElementById(areaId); 
	var scrollPos = txtarea.scrollTop; 
	var strPos = 0; 
	var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false ) ); 
		if (br == "ie") { txtarea.focus(); 
			var range = document.selection.createRange(); 
			range.moveStart ('character', -txtarea.value.length); 
			strPos = range.text.length; 
		} else if (br == "ff") strPos = txtarea.selectionStart; 
				var front = (txtarea.value).substring(0,strPos); 
				var back = (txtarea.value).substring(strPos,txtarea.value.length); 
				txtarea.value=front+text+back; 
				strPos = strPos + text.length; 
				if (br == "ie") { txtarea.focus(); 
					var range = document.selection.createRange(); 
					range.moveStart ('character', -txtarea.value.length); 
					range.moveStart ('character', strPos); 
					range.moveEnd ('character', 0); 
					range.select(); 
				} else if (br == "ff") { txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus(); 
					} 
			txtarea.scrollTop = scrollPos;
	imageblocks = imageblocks + 1;
	}	
		
	function getimageurl() {
	var theurl = prompt("enter Image URL");
	if (theurl!=null && theurl!="")
		{
		var imgtag = '<img src=\"' + theurl + '\" alt=\"there used to be an image here\" />';
		insertAtCaret('messageBody',imgtag);
		}
	}
	
	function makealink() {
	var linkurl = prompt("enter full link URL");
	if (linkurl!=null && linkurl!="")
		{
		var linkname = prompt("display link as(leave blank to show URL):");
			if (linkname!=null && linkname!="")
				{
				var linktag = '<a href=\"' + linkurl + '\">' + linkname + '</a>';
				insertAtCaret('messageBody',linktag);
				}
			else
				{
				var linktag = '<a href=\"' + linkurl + '\">' + linkurl + '</a>';
				insertAtCaret('messageBody',linktag);
			}
	}
	}
	
	function center(areaId) {
	var txtarea = document.getElementById(areaId);
	var sel = (txtarea.value).substring(txtarea.selectionStart,txtarea.selectionEnd);
		if (sel!="")
			{
			var strPos = txtarea.selectionStart;
			var endPos = txtarea.selectionEnd; 
			var front = (txtarea.value).substring(0,strPos); 
			var back = (txtarea.value).substring(txtarea.selectionEnd,txtarea.value.length); 
			txtarea.value= front + '<span class=\"center\">' + sel + '</span>' + back;
			strPos = endPos + 28;
			txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus();
			}
		else
			{
			window.alert('You can center text that has already been entered by hilighting it first');
			var cen = '<span class=\"center\"></span>';
			insertAtCaret('messageBody',cen);
			var endPos = txtarea.selectionEnd;
			var strPos = endPos - 7;
			txtarea.selectionStart = strPos; txtarea.selectionEnd = strPos; txtarea.focus();
			}
	}
</script>

	<form action="<?php echo current_url(); ?>" method="post">
	<fieldset><legend>Edit Post</legend>
	
	<br /><br />
	
	<p><b>Type:</b>&nbsp;<input type="text" name="type" size="10" maxlength="10" value="<?php echo $post->class; ?>" /></p>
	
	<p><i>Series:</i>&nbsp;<input type="text" name="series" size="4" maxlength="4" value="<?php echo $post->series; ?>" />&nbsp;&nbsp;<a href="<?php echo site_url('admin/list_series/'); ?>" target="_blank">#Find the Series ID on this list#</a></p>
	
	<p><i>Episode:</i>&nbsp;<input type="text" name="ep" size="3" maxlength="4" value="<?php echo $post->episode; ?>" /> * A 0 episode is used for series previews, 99 is used for final reviews.</p>
	
	<p><b>Title:</b>&nbsp;<input type="text" name="title" size="75" maxlength="256" value="<?php echo $post->title; ?>" /></p><br /><br />
	
	<p><b>Post:</b><br />
    <input type="button" value="Insert Automatic Image Block" onclick="imgblk('messageBody');" />&nbsp;&nbsp;
    <input type="button" value="Insert Image" onclick="getimageurl();" />&nbsp;&nbsp;
    <input type="button" value="Insert Link" onclick="makealink();" />&nbsp;&nbsp;
    <input type="button" value="Center Tag" onclick="center('messageBody');" /><br />
    
	<textarea name="content" id="messageBody" rows="20" cols="75"><?php echo $post->content; ?></textarea></p><br /><br />
	
	<div align="center"><input type="submit" name="submit" value="Edit Post" /></div><br /><br />
	
	</form><!-- End of Form -->	
	</div>
</div>

</body>
</html>